/**
 * SEVAS - Swiss Electronic Vaccination Advisor Service / Agile Development
 *
 * $Id: Application.java 29 2010-08-18 16:51:14Z zimmr7@bfh.ch $
 */
package ch.bfh.sevas.gui;

import ch.bfh.sevas.BaseVaccinationCatalog;
import java.awt.Point;
import java.awt.event.MouseEvent;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;

class VaccinationScheduleToolTipHeader extends JTableHeader {
    private final static Point NO_TIP = new Point(-2, -2);
    private Point toolTipLocation = NO_TIP;
    private BaseVaccinationCatalog vaccinationCatalog;

    public VaccinationScheduleToolTipHeader(final TableColumnModel model) {
        super(model);
        vaccinationCatalog = BaseVaccinationCatalog.getFilledBaseVaccineCatalog();
    }

    @Override
    public Point getToolTipLocation(final MouseEvent event) {
        toolTipLocation = event.getPoint();
        toolTipLocation.y -= 20;
        return toolTipLocation;
    }

    @Override
    public String getToolTipText(final MouseEvent event) {
        int column = columnModel.getColumnIndexAtX(event.getX());
        TableColumn aColumn = columnModel.getColumn(column);
        int modelColumn = aColumn.getModelIndex();
        if (modelColumn > 0) {
            String tip = vaccinationCatalog.getAllVaccinations().get(modelColumn - 1).getAntigen();
            return tip;
        } else if (modelColumn == 0) {
            return "Age";
        }

        return null;
    }
}